package com.editso.haier.controller.user;

import com.editso.haier.entity.User;
import com.editso.haier.result.Result;
import com.editso.haier.service.UserService;
import com.editso.haier.util.Utils;
import org.apache.shiro.authz.annotation.RequiresUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.Map;

@RestController
public class UserController {
    private UserService userService;

    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    @PostMapping("/login")
    public Result login(@RequestBody Map<String, Object> map){
        System.out.println(map);
        return userService.login(
                map.get("username").toString(),
                map.get("password").toString(),
                Boolean.parseBoolean(String.valueOf(map.get("remember"))));
    }

    @PostMapping("/register")
    public Result register(@RequestBody User user){
        return userService.register(user);
    }

    @GetMapping("/user/{id}")
    @RequiresUser
    public Result queryInfo(@PathVariable String id){
        return userService.queryInfo();
    }
}
